package com.shine.app.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

	private static final int DATABASE_VERSION = 1;
	private static final String DATABASE_NAME = "opentee";
	public static final String TABLE_NAME = "location";

	public DatabaseHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
	}

	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		StringBuffer buffer = new StringBuffer();
		buffer.append("CREATE TABLE [" + TABLE_NAME + "] (");
		buffer.append("[_id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ");
		buffer.append("[name] TEXT,");
		buffer.append("[latitude] double ,");
		buffer.append("[longitude] double ,");
		buffer.append("[distance] double ,");
		buffer.append("[stateCode] TEXT ,");
		buffer.append("[address] TEXT ,");
		buffer.append("[city] TEXT ,");
		buffer.append("[zipCode] TEXT ,");
		buffer.append("[createdTime] TimeStamp NOT NULL DEFAULT CURRENT_TIMESTAMP )");
		db.execSQL(buffer.toString());

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		onCreate(db);
	}

	@Override
	public void onOpen(SQLiteDatabase db) {
		super.onOpen(db);
	}

}
